import request from '@/axios';
import {baseUrl} from '@/config/env';

export const list = (data) => {
    return request({
            url: baseUrl + '/start/dataSource/table/page',
            method: 'get',
            params: data
        }
    )
}
export const add = (data) => {
    return request({
            url: baseUrl + '/start/dataSource/table/add',
            method: 'post',
            data: data
        }
    )
}
export const updateById = (data) => {
    return request({
            url: baseUrl + '/start/dataSource/table/updateById',
            method: 'put',
            data: data
        }
    )
}
export const deleteById = (id) => {
    return request({
            url: baseUrl + '/start/dataSource/table/deleteById/' + id,
            method: 'delete',
        }
    )
}

export const createCode = (dataSourcesKey, data) => {
    return request({
            url: baseUrl + '/start/dataSource/table/createCode/' + dataSourcesKey,
            method: 'post',
            responseType: 'blob',
            data
        }
    )
}
export const saveOrUpdate = (data) => {
    if (data.id) {
        return updateById(data)
    }
    return add(data)
}

/**
 * 生成代码
 * @param tableIds
 * @returns {AxiosPromise}
 */
export const genCode = (tableIds) => {
    return request({
            url: baseUrl + '/start/dataSource/table/genCode/' + tableIds,
            method: 'get',
            responseType: 'blob'
        }
    )
}
